package com.ruoyi.business.controller;

import com.ruoyi.business.domain.HomeworkQuestion;
import com.ruoyi.business.domain.HomeworkStuAnswer;
import com.ruoyi.business.domain.bo.EvaluationBo;
import com.ruoyi.business.domain.bo.HomeworkStuAnswerBo;
import com.ruoyi.business.domain.vo.EvaluationVo;
import com.ruoyi.business.domain.vo.QuestionVo;
import com.ruoyi.business.service.IEvaluationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author 最爱喝兽奶
 * @create 2022/9/29
 **/
@RestController
@RequestMapping("/business/evaluation")
public class EvaluationController extends BaseController {

    @Autowired
    private IEvaluationService evaluationService;

    @ApiOperation("提交互评信息")
    @GetMapping("/submit")
    public AjaxResult submitEvaluation(@RequestParam("homeworkId") String homeworkId,
                                       @RequestParam(value = "copies", defaultValue = "5") Integer copies,
                                       @RequestParam(value = "endTime") String endTime) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        evaluationService.submitEvaluation(homeworkId, copies, sdf.parse(endTime));
        return AjaxResult.success();
    }

    @ApiOperation("查询互评列表")
    @GetMapping("/list")
    public AjaxResult list(EvaluationBo bo) {
        TableDataInfo<EvaluationVo> vos = evaluationService.selectByPage(bo);
        return AjaxResult.success(vos);
    }

    @ApiOperation("查询问题信息")
    @GetMapping("/questions")
    public AjaxResult queryQuestionByEvaluation(EvaluationBo bo) {
        List<QuestionVo> vos = evaluationService.queryQuestionsByEvaluation(bo);
        return AjaxResult.success(vos);
    }


}
